package com.gitee.hermer.engine.jars.core.loader.event.listener;

import java.io.File;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.stereotype.Component;

import com.gitee.hermer.boot.jee.commons.bean.utils.BeanLocator;
import com.gitee.hermer.boot.jee.commons.log.UtilsContext;
import com.gitee.hermer.boot.jee.commons.reflect.ClassUtils;
import com.gitee.hermer.boot.jee.commons.verify.Assert;
import com.gitee.hermer.engine.jars.core.domain.EngineConstant;
import com.gitee.hermer.engine.jars.core.loader.EngineAppBeanScanner;

public class EngineRootApplicationRefreshHandle extends UtilsContext implements ApplicationListener<ContextRefreshedEvent>,ApplicationEventPublisherAware {


	private ApplicationEventPublisher publisher;

	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		File[] initJars = EngineAppBeanScanner.getMonitorWorkJarFiles();
		for (File file : initJars) {
			try{
				publisher.publishEvent(EngineAppBeanScanner.createEngineAppInitializationEvent(file));
			}catch (Exception e) {
				error(e.getMessage(),e);
			}
		}
	}

	@Override
	public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
		this.publisher = applicationEventPublisher;
	}

}
